package io.github.cocoa.module.socket.mq.producer.sample;

import io.github.cocoa.framework.common.core.KeyValue;
import io.github.cocoa.module.socket.mq.message.sample.SampleInfoMessage;
import io.github.cocoa.module.socket.mq.message.sample.SampleInfoOneMessage;
import io.github.cocoa.module.socket.mq.message.sample.SampleInfoTwoMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 示例信息 相关消息的 Producer
 *
 * @author James
 */
@Slf4j
@Component
public class SampleInfoProducer {

    @Resource
    private ApplicationContext applicationContext;

    /**
     * 发送 {@link SampleInfoMessage} 消息
     *
     * @param logId          示例编号
     * @param templateParams 示例模板参数
     */
    public void sampleSendMessage(Long logId, List<KeyValue<String, Object>> templateParams) {
        SampleInfoMessage message = new SampleInfoMessage().setLogId(logId).setTemplateParams(templateParams);
        applicationContext.publishEvent(message);
    }

    /**
     * 发送 {@link SampleInfoMessage} 消息 - 方法一
     *
     * @param logId          示例编号
     * @param templateParams 示例模板参数
     */
    public void oneMethodMessage(Long logId, List<KeyValue<String, Object>> templateParams) {
        SampleInfoOneMessage message = new SampleInfoOneMessage().setLogId(logId).setTemplateParams(templateParams);
        applicationContext.publishEvent(message);
    }

    /**
     * 发送 {@link SampleInfoMessage} 消息 - 方法二
     *
     * @param logId          示例编号
     * @param templateParams 示例模板参数
     */
    public void twoMethodMessage(Long logId, List<KeyValue<String, Object>> templateParams) {
        SampleInfoTwoMessage message = new SampleInfoTwoMessage().setLogId(logId).setTemplateParams(templateParams);
        applicationContext.publishEvent(message);
    }

}
